<template>
	<view class="_showModal" v-show="show">
		<view class="_shade"></view>
		<view class="_modalBox">
			<view class="_modal">
				<slot name="title">
					<view class="title" v-if="title">{{ title }}</view>
				</slot>
				<slot name="content">
					<view class="content"> {{ content }}</view>
				</slot>
				<slot name="btn">
					<view class="btnbox">
						<view class="btn cancel" @click.stop="clickBtn('cancel')" v-if="showCancel"> {{ cancelText }}</view>
						<view class="btn confirm" :class="!showCancel?'flex-1':''" @click.stop="clickBtn('confirm')">{{ confirmText }}</view>
					</view>
				</slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "show-modal",
		data() {
			return {
				plusModal: null,
			}
		},
		computed: {
			show() {
				return this.$modalStore.state.show;
			},
			title() {
				return this.$modalStore.state.title;
			},
			content() {
				return this.$modalStore.state.content;
			},
			showCancel() {
				return this.$modalStore.state.showCancel;
			},
			cancelText() {
				return this.$modalStore.state.cancelText;
			},
			cancelColor() {
				return "color:" + this.$modalStore.state.cancelColor;
			},
			confirmText() {
				return this.$modalStore.state.confirmText;
			},
			confirmColor() {
				return "color:" + this.$modalStore.state.confirmColor;
			}
		},
		methods: {
			closeModal() {
				this.$modalStore.commit('hideModal');
			},
			clickBtn(res) {
				this.$modalStore.commit('hideModal');
				this.$modalStore.commit('success', res);
			}
		},
		mounted() {
			
		},
		beforeDestroy() {
			this.$modalStore.commit('hideModal');
		}
	}
</script>

<style lang="scss" scoped>
	._showModal {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100vh;
		z-index: 10000;
	
		._shade {
			width: 100%;
			height: 100vh;
			position: absolute;
			top: 0;
			left: 0;
			background: #000;
			opacity: 0.6;
			z-index: 11000;
		}
	
		._modalBox {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 12000;
			display: flex;
			justify-content: center;
			align-items: center;
	
			._modal {
				flex: none;
				width: 500rpx;
				background: #fff;
				border-radius: 12rpx;
	
				.title {
					padding-top: 20rpx;
					text-align: center;
					font-size: 32rpx;
					font-weight: bold;
					color: #1d1d1f;
				}
	
				.content {
					padding: 40rpx 0;
					margin: 40rpx auto;
					font-size: 32rpx;
					color: #1d1d1f;
					display: flex;
					justify-content: center;
					align-items: center;
					text-align: center;
				}
	
				.btnbox {
					display: flex;
					margin: 0 62rpx;
					padding-bottom: 40rpx;
					flex-direction: row;
					justify-content: space-between;
	
					.btn {
						width: 160rpx;
						height: 64rpx;
						line-height: 64rpx;
						border-radius: 50rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 26rpx;
					}
	
					.cancel {
						background: #eee;
						font-weight: 400;
						color: #666;
					}
	
					.confirm {
						background: $theme-color;
						font-weight: 400;
						color: #fff;
					}
				}
			}
		}
	}
</style>